package io.renren.modules.package_storage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.package_storage.dao.V9PackageStorageDao;
import io.renren.modules.package_storage.entity.V9PackageStorageEntity;
import io.renren.modules.package_storage.service.V9PackageStorageService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("v9PackageStorageService")
public class V9PackageStorageServiceImpl extends ServiceImpl<V9PackageStorageDao, V9PackageStorageEntity> implements V9PackageStorageService {
    @Autowired
    V9PackageStorageService v9PackageStorageService;
    @Autowired
    V9PackageStorageDao v9PackageStorageDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
    	String user_code = (String)params.get("u_code");
    	String in_tracking_number = (String)params.get("in_tracking_number");
    	String statusStr = (String)params.get("status");
    	Integer status=null;
    	if (StringUtils.isNotBlank(statusStr)) {
    		status=Integer.parseInt(statusStr);
		}
        IPage<V9PackageStorageEntity> page = this.page(
                new Query<V9PackageStorageEntity>().getPage(params,"id",false),
                new QueryWrapper<V9PackageStorageEntity>()
                .like(StringUtils.isNotBlank(user_code),"user_code", "%"+user_code+"%")
                .like(StringUtils.isNotBlank(in_tracking_number),"in_tracking_number","%"+in_tracking_number+"%")
                .eq(status != null,"status", status)
        );

        return new PageUtils(page);
    }

	@Override
	public PageUtils getPackageList(Map<String, Object> params) {
		String u_code = (String)params.get("u_code");
    	Integer status=0;
        IPage<V9PackageStorageEntity> page = this.page(
                new Query<V9PackageStorageEntity>().getPage(params,"id",false),
                new QueryWrapper<V9PackageStorageEntity>()
                .eq(StringUtils.isNotBlank(u_code),"u_code", u_code)
                .eq(status != null,"status", status)
        );

        return new PageUtils(page);
	}

    @Override
    public R parcelcount(String uCode) {

        return v9PackageStorageDao.parcelcount(uCode);
    }

}
